package servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import session.UserDao;

/**
 * Kontroler koji služi za listiranje strelaca.
 * @author en_e
 *
 */
public class ScoreRankings extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@EJB
	protected UserDao userDao ;
	 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			if(request.getSession().getAttribute("user")==null){
				response.sendRedirect(response.encodeURL("./login.jsp"));
				return;
			}
			
			request.setAttribute("users", userDao.getScoreRanking());
			getServletContext().getRequestDispatcher("/scoreRankings.jsp").forward(request, response);
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
